package sort;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author XY
 * @version 1.0
 * @date 2022/3/14 10:53
 * @Description
 */
public class Leet455 {

    public static int findContentChildren1(int[] g, int[] s) {
        Map<Integer,Integer> map = new HashMap<>();
        Arrays.sort(g);
        for (int i = g.length - 1; i >= 0; i--) {
            for (int j = 0; j < s.length; j++) {
                if(s[j]>=g[i]){
                    if(map.get(j)==null){
                        map.put(j,s[j]);
                        break;
                    }
                }
            }
        }
        return map.size();
    }


    public static int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int i=0,j=0;
        int count =0 ;
        while(i<g.length&&j<s.length){
            if(s[j]>=g[i]){
                count++;
                j++;
                i++;
            }else{
                j++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        int[] arr1={ 1,1};
        System.out.println(findContentChildren(arr, arr1));
    }
}
